<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <father-page></father-page>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const ChildPage1 = {
      template: `
        <div>
          <h3>子组件1</h3>
          {{ a }}
          {{ b }}
        </div>
      `,
      // 注入依赖 注入父组件 provide提供的依赖
      inject: ['a', 'b']
    }
    const ChildPage2 = {
      template: `
        <div>
          <h3>子组件2</h3>  
          {{a}}
          {{b}}
          {{c}}
        </div>
      `,
      inject: ['a', 'b', 'c']
    }
    // 创建父组件
    const FatherPage = {
      template: `
        <div>
          <h2>父组件</h2>  
          <child-page1></child-page1>
          <hr/>
          <child-page2></child-page2>
        </div>
      `,
      // 父组件 通过 provide属性 向外暴露数据
      provide: {
        a: 10,
        b: '这是b',
        c: [1,2,3,4]
      },
      components: {
        ChildPage1,
        ChildPage2
      }
    }
    
    const { createApp } = Vue;
    const app = createApp();
    app.component('FatherPage', FatherPage)
    app.mount('#app')
  </script>
</body>
</html>